// pages/appointment/mentdetailt.js
const app = getApp();
var comm = require('../../utils/util.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        id: 0,
        detail: {},
        colorlist: ["", "c-yellow", "c-purple", "c-red", "c-green", "c-9"]//状态颜色
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        console.log(options);
        wx.setNavigationBarTitle({
            title: '预约详情',
        })
        var _this = this;
        _this.setData({
            "id": options.id
        });
        _this.GetDetail(_this.data.id);
    },
    GetDetail: function (id) {
        app.http.POST("/MiniCardReserva/GetMyReservaDetail", { "id": id, "type": 2 }, (err, data) => {
            if (data.code == 1) {
                var detail = data.data;
                console.log(detail);
                detail.CTime = comm.dateFormat(data.data.CTime, "yyyy-MM-dd hh:mm");
                detail.ReTime = comm.dateFormat(data.data.ReTime, "yyyy年MM月dd日 hh时mm分");
                var showbtn = this.data.showbtn;
                if (data.data.Status == 2) {
                    showbtn = true;
                }
                this.setData({
                    "detail": detail
                });
            }
            else {
                wx.showToast({
                    title: '获取数据失败',
                    icon: 'none',
                    duration: 2000
                })
            }
        });
    },
    //处理预约
    HandleReserva: function (e) {
        var dataset = e.currentTarget.dataset;
        var id = dataset.id;
        var status = dataset.status;
        var _this = this;
        app.http.POST("/MiniCardReserva/HandleReserva", { "id": id, "status": status }, (err, data) => {
            if (data.code == 1) {
                wx.showToast({
                    title: '操作成功',
                    icon: 'none',
                    duration: 2000,
                    success: function () {
                        wx.redirectTo({
                            url: "appointment"
                        })
                    }
                });
                //更新页面
            } else {
                wx.showToast({
                    title: '操作失败',
                    icon: 'none',
                    duration: 2000
                })
            }
        });
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
        var userInfo = app.globalData.userInfo;
        //判断当前用户是否开通服务,开通则分享美名片页,否则分享访问记录页
        if (userInfo == null || typeof (userInfo) == "undefined") {
            app.getUserall(function (res) {
                userInfo = res;
            });
        }
        var path = userInfo.UserType == 2 ? "/pages/index/index?cid=" + userInfo.Id : "/pages/cardrecord/cardrecord";
        return {
            title: userInfo.NickName + "的美名片",
            path: path,
            success: function (res) {
                wx.showToast({
                    title: '分享成功',
                    icon: "success",
                    duration: 200
                })
            }
        }
    }
})